#include "head.h"
#include "queue.h"
#include <pthread.h>

void* thread_main(void* p){

    status_t* status = (status_t *)p;

    while(1){

        int net_fd = 0;
        pthread_mutex_lock(&status->lock);

        while(status->queue.size <= 0 && status->exit_flag == 0){
            pthread_cond_wait(&status->cond,&status->lock);
        }
        if(status->exit_flag == 1){
            pthread_mutex_unlock(&status->lock);
            pthread_exit(NULL);
        }

        net_fd = status->queue.head->net_fd;

        deQueue(&status->queue);

        pthread_mutex_unlock(&status->lock);

        work(net_fd);

        close(net_fd);


    }

    return NULL;
}














